<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>管理个人信息</title>
<link rel="stylesheet" type="text/css"href="static/bootstrap-3.3.7-dist/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css"href="static/bootstrap-3.3.7-dist/css/bootstrap-theme.min.css" />
<link rel="icon" type="image/png" href="${basePath}static/adminManager/assets/i/favicon.png">
<link rel="apple-touch-icon-precomposed" href="${basePath}static/adminManager/assets/i/app-icon72x72@2x.png">
<link rel="stylesheet" href="${basePath}static/adminManager/assets/css/amazeui.min.css" />
<link rel="stylesheet" href="${basePath}static/adminManager/assets/css/admin.css">
<link rel="stylesheet" href="${basePath}static/adminManager/add/css/add.css">
<!-- 引入layui -->
<link rel="stylesheet" type="text/css" href="static/layui-v2.4.5/css/layui.css" />
<style>
	.registe-content{
		margin-left:80px;
		padding-top:15px;
	}
	.bootint{width:570px !important;}
	.input-span-text{width:120px !important;}
	.form-control3{width:450px !important;}
	#rebtn{
		width:570px !important;
		margin-top:40px;
	}
	.admin_img{
		position: relative;
    	top: -280px;
    	right: 80px;
    	float: right;
    	padding-right:40px;
	}
</style>
</head>


<body id="pswbody">

<div class="admin-biaogelist">
	
   		<div class="listbiaoti am-cf">
      		<ul class="am-icon-flag on"> 个人信息管理</ul>
      		<dl class="am-icon-home" style="float: right;">当前位置： 首页 > <a href="#">个人信息管理</a></dl>
    	</div>
    	
<div class="am-g tpl-g" >
	<div class="tpl-login">
		<div class="tpl-login-content">

	<form   id="accountForm" class="form-horizontal"  enctype="multipart/form-data"
		action="ChangeAdminInfo"   method="post">
				
		<div  class="registe-content">
					
			<div class="bootint">
					<span class="input-span-text ">昵称：</span>
					<input type="text" class="form-control3" id="adminname"name="adminname" 
					value="<%=session.getAttribute("adminName") %>" placeholder="4~8为非空字符">
					<!-- 隐藏表单，用于储存管理员编号 -->
					<input type="hidden" id="adminid" name="adminid" value="<%=session.getAttribute("adminId") %>" />
				</div>
				
			<div class="bootint">
				<span class="input-span-text ">地址：</span>
				<input type="text" class="form-control3" id="adminaddress"name="adminaddress" value="<%=session.getAttribute("adminAddress") %>">
			</div>
				
			<div class="bootint">
				<span class="input-span-text ">联系方式：</span>
				<input type="text" class="form-control3" id="admintel"name="admintel" value="<%=session.getAttribute("adminTel") %>">
			</div>
			
			<div class="bootint" style="margin-top:300px;">
					<button type="submit" class="btn btn-success btn-lg"  id="rebtn" onclick="return checkMe()" >提交</button>
			</div>
					
		</div>
				
			<div class="admin_img">
				<!-- 当前头像，若是没有上传头像，则显示默认图片   onerror="this.src='static/adminManager/img/defaultImg.png';this.onerror=null;-->
				<img alt="当前头像"
					src="<%=session.getAttribute("adminImg") %>" width="200px;" height="200px;"id="viewuserpicture">
				<div style="margin-top:10px;">
					<input name="fileName" readonly style="width:120px;height:30.5px"/>
					<input type="button" value="修改头像"  class="btn-sm"
						onclick="javascript:$('input[name=\'file_adminimg\']').click();" />
					<input type="file" id="adminimg"name="file_adminimg" style="display: none;"
						onchange="javascript:$('input[name=\'fileName\']').val(this.files[0].name);" />
				</div>
			</div>
			
	</form>
	
</div></div></div></div>

</body>


<script type="text/javascript"src="static/jquery-1.12.4/jquery-1.12.4.min.js"></script>
<script type="text/javascript"src="static/layer-v3.1.1/layer/layer.js"></script>


<!-- 表单验证 -->
<script type="text/javascript">
	 // 验证form表单是否合法
	function checkMe() {
		// 错误提示信息
		var strMsg = "";
		// 用户昵称验证
		var regName = /^.\S{3,7}$/;
		var username = document.getElementById("adminname").value;
		if (username == null || username == ""|| regName.test(username) === false) {
			// 增加提示信息
			strMsg += "请输入正确的用户名!<br>";
		}
		// 居住地验证
		var userlocation = document.getElementById("adminaddress").value;
		if (userlocation == null || userlocation == "") {
			// 增加提示信息
			strMsg += "请输入居住地 !<br>";
		}
		// 手机号验证
		var regModile = /^1\d{10}$/;
		var usertel = document.getElementById("admintel").value;
		if (usertel == null || usertel == ""	|| regModile.test(usertel) === false) {
			// 增加提示信息
			strMsg += "请输入正确的手机号!<br>";
		}
		
		// 判定整个表单是否可以进行提交
		if (strMsg == "") {
			// 验证通过
			//layer.alert('修改成功', {icon: 1});
			return true;
		} else {
			// 验证不通过
			layer.open({
				icon:2,
				title : '提示',
				content : strMsg
			});
			return false;
		}
	}
	// 手动提交form表单
	function doSubmit() {
		document.getElementById("accountForm").submit();
	}
</script>

<!-- 选择完图片即显示浏览 -->
<script type="text/javascript">
$(function() {
    $("#adminimg").change(
       function() {
           var $file = $(this);
           var fileObj = $file[0];
           var windowURL = window.URL || window.webkitURL;
 /*URL对象是硬盘（SD卡等）指向文件的一个路径，如果我们做文件上传的时候，想在没有上传服务器端的情况下看到上传图片的效果图的时候就可以
 通过var url=window.URL.createObjectURL(obj.files[0]);获得一个http格式的url路径，这个时候就可以设置到<img>中显示了。*/
           var dataURL;
           var $img = $("#viewuserpicture");
           //当图片名称为空时，照片不显示。
           if(document.getElementById('adminimg').value.trim()==""){
               document.getElementById('tr_userpicture').style.display = 'none';
            }
           if (fileObj && fileObj.files && fileObj.files[0]) {
               dataURL = windowURL.createObjectURL(fileObj.files[0]);
               //允许上传的图片格式  
               var newPreview = document.getElementById("adminimg").value;
               var regext = /\.jpg$|\.gif$|\.jpeg$|\.png$|\.bmp$/gi;
               if (!regext.test(newPreview)) {
                   newPreview=="";
                   alert("选择的照片格式不正确，请重新选择！");
                    $(fileObj).after($(fileObj).clone($(fileObj)));
                     $(fileObj).remove();
                     $("#tr_userpicture").hide();
                   return false;
               }
               $img.attr("src", dataURL);
               $("#tr_userpicture").show();

           } else {
               dataURL = $file.val();
               var imgObj = document.getElementById("viewuserpicture");

               imgObj.style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(sizingMethod=scale)";
               imgObj.filters
                       .item("DXImageTransform.Microsoft.AlphaImageLoader").src = dataURL;
           }
       });
   });
</script>

<!-- 若用户没有上传头像则显示默认头像 -->
<script type="text/javascript">
    $(function(){
        $('img').each(function(){
        	var objImg=<%=session.getAttribute("adminImg") %>;
            if( objImg==null){
                $(this).attr('src','static/adminManager/img/timg.jpg');
            }
        });
    })
</script>=
</html>
